//
//  YesterdayViewController.m
//  BasketballClub
//
//  Created by lanou3g on 16/1/6.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "YesterdayViewController.h"
#import "LiveTableViewCell.h"
#import "LiveHandle.h"
#import "LiveModel.h"
#import <MJRefresh.h>
#import "WebViewController.h"
@interface YesterdayViewController ()<UITableViewDataSource,UITableViewDelegate,LiveTableViewCellDelegate>
///定义一个tableView
@property(nonatomic,strong)UITableView *yesterdayTableView;

@end

@implementation YesterdayViewController
#pragma mark  -  重新加载视图

- (void)viewDidLoad {
    [super viewDidLoad];
    //布局tableView
    self.yesterdayTableView  = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-148*LAYOUT_SIZE_HEIGHT) style:UITableViewStylePlain];
   
    [self.view addSubview:self.yesterdayTableView];
    
    
    //设置为代理
    self.yesterdayTableView.delegate = self;
    self.yesterdayTableView.dataSource = self;
   
    //注册cell
    [self.yesterdayTableView registerClass:[LiveTableViewCell class] forCellReuseIdentifier:@"LiveTableViewCellYesterday"];
    //数据的回调刷新
    [[LiveHandle sharedLiveHandle] GetYesterdayDataFromNetWorkWithBlock:^(BOOL isFinished) {
        [self.yesterdayTableView reloadData];
        
    }];
    

}



#pragma mark - tableViewDataSoucre
/// rows
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [LiveHandle sharedLiveHandle].liveYesterdayDataArray.count;
}
/// cell的重用和赋值
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LiveTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"LiveTableViewCellYesterday"];
    if ([LiveHandle sharedLiveHandle].liveYesterdayDataArray.count) {
        LiveModel *model = [LiveHandle sharedLiveHandle].liveYesterdayDataArray[indexPath.row];
        [cell setCellDataFromLiveModel:model];

    }
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
       cell.delegate = self;
    
        
    return cell;
}
#pragma mark - 代理方法 技术统计
///
-(void)LiveTableViewCellCountBtnDidClicked:(LiveTableViewCell *)cell
{
    NSIndexPath *indexPath = [self.yesterdayTableView indexPathForCell:cell];
    LiveModel *liveModel = [LiveHandle sharedLiveHandle].liveYesterdayDataArray[indexPath.row];
    NSString *urlString = liveModel.link2url;
    [self jumpToWebViewWith:urlString];
    

}

#pragma mark  -代理方法 文字/视频直播方法
-(void)LiveTableViewCellVideoOrTextBtnDidClicked:(LiveTableViewCell *)cell
{
    NSIndexPath *indexPath = [self.yesterdayTableView indexPathForCell:cell];
 
    LiveModel *liveModel = [LiveHandle sharedLiveHandle].liveYesterdayDataArray[indexPath.row];
    NSString *urlString = liveModel.m_link1url;
    [self jumpToWebViewWith:urlString];
 

}
#pragma mark - 跳转到webView
-(void)jumpToWebViewWith:(NSString *)str
{
    NSURL *url = [NSURL URLWithString:str];
    WebViewController *webViewVC =[[WebViewController alloc]init];
    webViewVC.url = url;
    
    [self.navigationController pushViewController:webViewVC animated:YES];
    
}





#pragma mark  -  cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 190*LAYOUT_SIZE_HEIGHT;
}
#pragma mark  -  Cell的点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [LiveHandle sharedLiveHandle].liveYesterdayDataArray = nil;
}






























//#pragma mark - 下拉刷新
//-(void)upData
//{
//    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshAction)];
//
//    self.yesterdayTableView.mj_header = header;
//    [self.yesterdayTableView.mj_header beginRefreshing];
//
//
//}
//#pragma mark  - 刷新执行的方法
//-(void)refreshAction
//{
//    [LiveHandle sharedLiveHandle].liveYesterdayDataArray = nil;
//    __weak typeof(self) weakSlef = self;
//    [[LiveHandle sharedLiveHandle] GetYesterdayDataFromNetWorkWithBlock:^(BOOL isFinished) {
//        if (isFinished) {
//            [weakSlef.yesterdayTableView reloadData];
//        }else{
//
//            [[LiveHandle sharedLiveHandle] GetYesterdayDataFromNetWorkWithBlock:^(BOOL isFinished) {
//
//            }];
//        }
//        [self.yesterdayTableView.mj_header endRefreshing];
//    }];
//
//
//}



@end
